<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class News_model extends CI_Model { 
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
	
    public function getNewsList()
    {
        $query = 
            "SELECT 
                psacar_news.id AS Id,
                psacar_news_category.title AS Category,
                psacar_news.news_cat_id,
                psacar_news.title AS Title,
                psacar_news.short_description AS ShortDesc,
                psacar_news.description AS Description,
                psacar_news.image_news AS Image,
                psacar_news.thumbnail_news AS Thumbnail,
                psacar_news.post_date AS PostDate
            FROM
                psacar_news
                INNER JOIN psacar_news_category ON psacar_news_category.id = psacar_news.news_cat_id 
            ORDER BY PostDate";

        $result=$this->db->query($query);
        return  $result;
    }

    public function getGasPrice()
    {
        $query = "SELECT price FROM psacar_gas_price";
        $result = $this->db->query($query);
        return  $result;
    }

    public function getNewsListByCategory($category_id)
    {
        $query = 
            "SELECT 
                psacar_news.id AS Id,
                psacar_news_category.title AS Category,
                psacar_news.news_cat_id,
                psacar_news.title AS Title,
                psacar_news.short_description AS ShortDesc,
                psacar_news.description AS Description,
                psacar_news.image_news AS Image,
                psacar_news.thumbnail_news AS Thumbnail,
                psacar_news.post_date AS PostDate,
                psacar_news.modified_date
            FROM
                psacar_news
                INNER JOIN psacar_news_category ON psacar_news_category.id = psacar_news.news_cat_id 
            WHERE
                psacar_news_category.id = '$category_id' 
            ORDER BY PostDate DESC";

        $result=$this->db->query($query);
        return  $result;
    }
        
    public function getNewsListById($Id)
{
        $query = 
            "SELECT
                psacar_news_category.title AS Category,
                psacar_news.news_cat_id,
                psacar_news.title AS Title,
                psacar_news.short_description AS ShortDesc,
                psacar_news.description AS Description,
                psacar_news.image_news AS Image,
                psacar_news.thumbnail_news AS Thumbnail,
                psacar_news.post_date AS PostDate
            FROM
                psacar_news
                INNER JOIN psacar_news_category ON psacar_news_category.id = psacar_news.news_cat_id 
            WHERE psacar_news.Id = " . $Id . 
            " ORDER BY PostDate";

        $result=$this->db->query($query);
        return  $result;
    }             
}